﻿
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

using System.ComponentModel;
using Cms.Core.Infrastructure;

namespace Cms.Core.Infrastructure.Extension
{
  public static  class EnumExtensions
    {

        /// <summary>
        /// 转成显示名字
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public static string ToDisplayName(this Enum value)
        {
            var type = value.GetType();
            MemberInfo member = type.GetMember(value.ToString()).FirstOrDefault();
            var displayAttribute = member?.GetCustomAttributes<DisplayAttribute>()?.FirstOrDefault();
            return displayAttribute.IsNull()? member?.Name: displayAttribute?.DisplayName();
        }



    }
}
